import * as _ from "lodash"
import httpClient from "../httpclient"

export class PaymentMethodDescription {
  public code: string
  public name: string
  public logo: string
  public color: string
  public description: string
  public enabled: boolean
  public position: number
}

function assignPaymentMethod(method: PaymentMethodDescription) {
  return _.assign(new PaymentMethodDescription(), method)
}

class PaymentMethodQuery {

  private params = {}

  public enable(): PaymentMethodQuery {
    this.params["enabled"] = true
    return this
  }

  public disable(): PaymentMethodQuery {
    this.params["enabled"] = false
    return this
  }

  public list(): Promise<PaymentMethodDescription[]> {
    return httpClient.get("/v1/payments/methods", {
      params: this.params,
    }).then(({ data }) => _.map(data, assignPaymentMethod))
  }
}

export class PaymentMethodServiceV1 {
  public static getPaymentMethods(): PaymentMethodQuery {
    return new PaymentMethodQuery()
  }
}


